﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace _80X_CG_Frame.Objects
{
    /// <summary>
    /// 统计数据
    /// </summary>
    public class Statistics : INotifyPropertyChanged
    {
        int 下CG_count_ok;
        int 下CG_count_ng;
        int 上CG_count_ok;
        int 上CG_count_ng;
        int 上料扫码_count_ok;
        int 上料扫码_count_ng;

        string barcode;
        DateTime start_time;
        TimeSpan start_time_count;
        int round_count;
        string warning_stack;
        List<TimeSpan> time_per_round;
        TimeSpan average_time;

        public Statistics()
        {
            下CG_Count_OK = 0;
            下CG_Count_NG = 0;
            上CG_Count_OK = 0;
            上CG_Count_NG = 0;
            上料扫码_Count_OK = 0;
            上料扫码_Count_NG = 0;
            上CG_Barcode = "";
            启动时间 = DateTime.Now;
            运行时间 = new TimeSpan(0,0,0);
            回环线动作数 = 0;
            warning_stack = "";
            Time_per_round = new List<TimeSpan>();
            回环线动作平均时间 = new TimeSpan(0, 0, 0);

        }

        public int 下CG_Count_OK
        {
            get => 下CG_count_ok;
            set
            {
                下CG_count_ok = value;
                NotifyPropertyChanged();
            }
        }
        public int 下CG_Count_NG
        {
            get => 下CG_count_ng;
            set
            {
                下CG_count_ng = value;
                NotifyPropertyChanged();
            }
        }

        public string 上CG_Barcode
        {
            get => barcode; set
            {
                barcode = value;
                NotifyPropertyChanged();
            }
        }
        public int 上CG_Count_OK
        {
            get => 上CG_count_ok;
            set
            {
                上CG_count_ok = value;
                NotifyPropertyChanged();
            }
        }
        public int 上CG_Count_NG
        {
            get => 上CG_count_ng;
            set
            {
                上CG_count_ng = value;
                NotifyPropertyChanged();
            }
        }
        public int 上料扫码_Count_OK
        {

            get => 上料扫码_count_ok;
            set
            {
                上料扫码_count_ok = value;
                NotifyPropertyChanged();
            }
        }
        public int 上料扫码_Count_NG
        {
            get => 上料扫码_count_ng;
            set
            {
                上料扫码_count_ng = value;
                NotifyPropertyChanged();
            }
        }

        public TimeSpan 运行时间 { get => start_time_count; set { start_time_count = value; NotifyPropertyChanged();} }
        public int 回环线动作数 { get => round_count; set { round_count = value; NotifyPropertyChanged(); } }
        /// <summary>
        /// 告警栈
        /// </summary>
        public string Warning_stack
        {
            get => warning_stack; set
            {
                this.warning_stack = value;
                NotifyPropertyChanged();
            }
        }

        /// <summary>
        /// 每次回环线动作用时
        /// </summary>
        public List<TimeSpan> Time_per_round { get => time_per_round; set => time_per_round = value; }
        public DateTime 启动时间 { get => start_time; set => start_time = value; }
        public TimeSpan 回环线动作平均时间 { get => average_time; set { average_time = value; NotifyPropertyChanged(); } }

        public event PropertyChangedEventHandler PropertyChanged;
        // This method is called by the Set accessor of each property.
        // The CallerMemberName attribute that is applied to the optional propertyName
        // parameter causes the property name of the caller to be substituted as an argument.
        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
